#include "Mysocket.h"

bool Mysocket::SendString(wxSocketBase* sock,const wxString& msg)
{
	const wxCharBuffer umsg = msg.utf8_str();
	int len = strlen(umsg.data());
	if(sock->Write(&len,sizeof(int)).Error()) return false;
    if(sock->Write(umsg.data(),len).Error())
    {
        return false;
    }
    return true;
}

bool Mysocket::ReceiveString(wxSocketBase* sock,wxString& msg)
{
	int len;
	if(sock->Read(&len,sizeof(int)).Error()) return false;
	char* buff = new char[len+10];
    if(sock->Read(buff,len).Error())
    {
    	delete(buff);
        return false;
    }
    buff[len] = 0;
    msg = wxString(buff,wxConvUTF8);
    delete(buff);
    return true;
}
